VERSION 5.00
Begin VB.UserControl Panel 
   Alignable       =   -1  'True
   AutoRedraw      =   -1  'True
   BackColor       =   &H00F5F5F5&
   ClientHeight    =   1095
   ClientLeft      =   0
   ClientTop       =   0
   ClientWidth     =   1095
   ControlContainer=   -1  'True
   PropertyPages   =   "Panel.ctx":0000
   ScaleHeight     =   73
   ScaleMode       =   3  'Pixel
   ScaleWidth      =   73
   ToolboxBitmap   =   "Panel.ctx":0014
   Begin VB.PictureBox pnlPicture 
      AutoRedraw      =   -1  'True
      BorderStyle     =   0  'None
      ClipControls    =   0   'False
      Height          =   615
      Left            =   240
      ScaleHeight     =   41
      ScaleMode       =   3  'Pixel
      ScaleWidth      =   41
      TabIndex        =   0
      Top             =   240
      Visible         =   0   'False
      Width           =   615
   End
End
Attribute VB_Name = "Panel"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = True
Attribute VB_Ext_KEY = "PropPageWizardRun" ,"Yes"
'MappingInfo=UserControl,UserControl,-1,BackColor
Option Explicit

'Properties variables
Dim ctlBorder             As Boolean

'Private variables
Private m_BorderColor     As OLE_COLOR
Private c_BtnClickTracker As Integer

'Events declaration
Event Click(ByVal Button As Integer)
Event DblClick(ByVal Button As Integer)
Event MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Event MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Event MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
Event Resize()

' *********************************************************************************
' PROPERTIES
' *********************************************************************************

Public Property Get BackColor() As OLE_COLOR
    BackColor = UserControl.BackColor
End Property

Public Property Let BackColor(ByVal New_Color As OLE_COLOR)
    UserControl.BackColor() = New_Color
    Call RenderPanel
    PropertyChanged "BackColor"
End Property

Public Property Get Border() As Boolean
    Border = ctlBorder
End Property

Public Property Let Border(ByVal NewValue As Boolean)
    ctlBorder = NewValue
    Call RenderPanel
    PropertyChanged "Border"
End Property

Public Property Get BorderColor() As OLE_COLOR
    BorderColor = m_BorderColor
End Property

Public Property Let BorderColor(ByVal New_Color As OLE_COLOR)
    m_BorderColor = New_Color
    Call RenderPanel
    PropertyChanged "BorderColor"
End Property

Public Property Get Enabled() As Boolean
    Enabled = UserControl.Enabled
End Property

Public Property Let Enabled(NewValue As Boolean)
    UserControl.Enabled = NewValue
    Call RenderPanel
    PropertyChanged "Enabled"
End Property

Public Property Get MouseIcon() As Picture
    Set MouseIcon = UserControl.MouseIcon
End Property

Public Property Set MouseIcon(ByVal New_MouseIcon As Picture)
    Set UserControl.MouseIcon = New_MouseIcon
    PropertyChanged "MouseIcon"
End Property

Public Property Get MousePointer() As MousePointerConstants
    MousePointer = UserControl.MousePointer
End Property

Public Property Let MousePointer(ByVal New_MousePointer As MousePointerConstants)

    If New_MousePointer < vbDefault Then New_MousePointer = vbDefault
    If (New_MousePointer > vbSizeAll) And (New_MousePointer <> vbCustom) Then New_MousePointer = vbSizeAll
    UserControl.MousePointer() = New_MousePointer
    PropertyChanged "MousePointer"
End Property

Private Sub UserControl_ReadProperties(PropBag As PropertyBag)
    UserControl.BackColor = PropBag.ReadProperty("BackColor", &HF5F5F5)
    Border = PropBag.ReadProperty("Border", True)
    BorderColor = PropBag.ReadProperty("BorderColor", &HDBCECC)
    Enabled = PropBag.ReadProperty("Enabled", True)
    Set MouseIcon = PropBag.ReadProperty("MouseIcon", Nothing)
    UserControl.MousePointer = PropBag.ReadProperty("MousePointer", vbDefault)
End Sub

Private Sub UserControl_WriteProperties(PropBag As PropertyBag)
    Call PropBag.WriteProperty("BackColor", UserControl.BackColor, &HF5F5F5)
    Call PropBag.WriteProperty("Border", ctlBorder, True)
    Call PropBag.WriteProperty("BorderColor", m_BorderColor, &HDBCECC)
    Call PropBag.WriteProperty("Enabled", Enabled, True)
    Call PropBag.WriteProperty("MouseIcon", MouseIcon, Nothing)
    Call PropBag.WriteProperty("MousePointer", UserControl.MousePointer, vbDefault)
End Sub

' *********************************************************************************
' EVENTS
' *********************************************************************************

Private Sub pnlPicture_Click()
    RaiseEvent Click(c_BtnClickTracker \ &H10)
End Sub

Private Sub pnlPicture_DblClick()
    RaiseEvent DblClick(c_BtnClickTracker \ &H10)
End Sub

Private Sub pnlPicture_MouseDown(Button As Integer, _
                                 Shift As Integer, _
                                 X As Single, _
                                 Y As Single)
    c_BtnClickTracker = (c_BtnClickTracker Or Button)
    RaiseEvent MouseDown(Button, Shift, X, Y)
End Sub

Private Sub pnlPicture_MouseMove(Button As Integer, _
                                 Shift As Integer, _
                                 X As Single, _
                                 Y As Single)
    RaiseEvent MouseMove(Button, Shift, X, Y)
End Sub

Private Sub pnlPicture_MouseUp(Button As Integer, _
                               Shift As Integer, _
                               X As Single, _
                               Y As Single)
    c_BtnClickTracker = (c_BtnClickTracker And &HF)

    If (c_BtnClickTracker And Button) = Button Then c_BtnClickTracker = (c_BtnClickTracker Or Button * &H10)
    RaiseEvent MouseUp(Button, Shift, X, Y)
End Sub

' *********************************************************************************
' FUNCTION
' *********************************************************************************

Public Property Get hwnd() As Long
    hwnd = UserControl.hwnd
End Property

Public Sub Refresh()
    UserControl.Refresh
End Sub

' *********************************************************************************
' USER CONTROL
' *********************************************************************************

Private Sub UserControl_Click()
    RaiseEvent Click(c_BtnClickTracker \ &H10)
End Sub

Private Sub UserControl_DblClick()
    RaiseEvent DblClick(c_BtnClickTracker \ &H10)
End Sub

Private Sub UserControl_MouseDown(Button As Integer, _
                                  Shift As Integer, _
                                  X As Single, _
                                  Y As Single)
    c_BtnClickTracker = (c_BtnClickTracker Or Button)
    RaiseEvent MouseDown(Button, Shift, X, Y)
End Sub

Private Sub UserControl_MouseMove(Button As Integer, _
                                  Shift As Integer, _
                                  X As Single, _
                                  Y As Single)
    RaiseEvent MouseMove(Button, Shift, X, Y)
End Sub

Private Sub UserControl_MouseUp(Button As Integer, _
                                Shift As Integer, _
                                X As Single, _
                                Y As Single)
    c_BtnClickTracker = (c_BtnClickTracker And &HF)

    If (c_BtnClickTracker And Button) = Button Then c_BtnClickTracker = (c_BtnClickTracker Or Button * &H10)
    RaiseEvent MouseUp(Button, Shift, X, Y)
End Sub

Private Sub UserControl_Resize()
    On Error Resume Next

    If UserControl.Width < 255 Then UserControl.Width = 255
    If UserControl.Height < 255 Then UserControl.Height = 255
    pnlPicture.Width = UserControl.ScaleWidth
    pnlPicture.Height = UserControl.ScaleHeight
    Call RenderPanel
    RaiseEvent Resize
End Sub

Private Sub UserControl_Show()
    Call RenderPanel
End Sub

Private Sub UserControl_Initialize()
    BackColor = &HF5F5F5
    Border = True
    BorderColor = &HDBCECC
    Enabled = True
    UserControl_Resize
End Sub

' *********************************************************************************
' CUSTOM ROUTINES
' *********************************************************************************

Private Sub RenderPanel()

    With UserControl
        'Clear control.
        Call .Cls
        'Set the main panel backcolor
        .BackColor = BackColor

        'Draw the panels border.
        If ctlBorder Then
            UserControl.Line (0, 0)-(.ScaleWidth - 1, .ScaleHeight - 1), BorderColor, B
        Else
            UserControl.Line (0, 0)-(.ScaleWidth - 1, .ScaleHeight - 1), BackColor, B
        End If
    End With
End Sub
